<template>
  <div>
    <el-dialog
      title="编辑设备检定"
      :visible.sync="dialogVisible"
      width="50%"
    >
      <el-form labelWidth="150px">
        <el-form-item label="设备名称">
          {{editData.ep_ename}}
        </el-form-item>
        <el-form-item label="管理编号">
          {{editData.managenum}}
        </el-form-item>
        <el-form-item label="规格型号">
          {{editData.scale}}
        </el-form-item>
        <el-form-item label="检定/校准周期">
          {{editData.verifiy_round}}
        </el-form-item>
        <el-form-item label="下次检定/校准时间">
          {{editData.nextverifiytime}}
        </el-form-item>
        <el-form-item label="溯源方式">
          <el-input v-model="editData.traceability"></el-input>
        </el-form-item>
        <el-form-item label="检定/校准单位">
          <el-input v-model="editData.verifiy_company"></el-input>
          <el-select placeholder="筛选检定/校准单位" style="width:100%" @change="changejddw">
            <el-option
              v-for="item in jddwArr"
              :key="item.value"
              :label="item.hash.code_name"
              :value="item.hash.code_name"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="本次检定/校准日期">
          <el-date-picker
            valueFormat="yyyy-MM-dd"
            v-model="editData.verifiytime"
            type="date"
            style="width:100%"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="dialogVisible = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="sumitedit">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  props: {
    editData: {
      type: Object,
      required: true,
    },
  },
  created() {
    this.getcodeData('0405', '04', 'jddwArr');
    this.editData = Object.assign({}, this.editData);
  },
  data() {
    return {
      ts: this.newStore(),
      dialogVisible: true,
      jddwArr: [],
    };
  },
  methods: {
    changejddw(val) {
      this.editData.verifiy_company = val;
    },
    getcodeData(supid, codetype, arrname) {
      const req = {
        handle: '67A5B6FEF17D97DECF116BDF95B95C0B167942DD3F1604F9',
        supid,
        codetype,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this[arrname] = ts.d.data.operation1;
      });
    },
    // 提交编辑设备
    sumitedit() {
      this.$confirm('确认保存?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          const req = this.editData;
          req.handle = 'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7A2A135017DDC2CA80F83A87A369653E1B';
          console.log(req);

          this.spost(this.ts, '/mainservlet', req).then(() => {
            this.$message({
              type: 'success',
              message: '保存成功',
            });
            this.$parent.getschedulelist();
            this.dialogVisible = false;
          });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消',
          });
        });
    },
  },
};
</script>
